package org.bangumibuddy.pojo;
import lombok.Data;
import org.bangumibuddy.constant.ResponseStateConstant;

import java.io.Serializable;

@Data
public class ResponseResult<T> implements Serializable{
    private Integer code; //编码：200成功，500和其它数字为失败
    private String msg; //错误信息
    private T data; //数据

    public static <T> ResponseResult<T> success() {
        ResponseResult<T> result = new ResponseResult<>();
        result.code = ResponseStateConstant.SUCCESS;
        return result;
    }

    public static <T> ResponseResult<T> success(T object) {
        ResponseResult<T> result = new ResponseResult<>();
        result.data = object;
        result.code = ResponseStateConstant.SUCCESS;
        return result;
    }

    public static <T> ResponseResult<T> error(String msg) {
        ResponseResult result = new ResponseResult<>();
        result.msg = msg;
        result.code = ResponseStateConstant.ERROR;
        return result;
    }

    public static <T> ResponseResult<T> tokenerror(String msg) {
        ResponseResult result = new ResponseResult<>();
        result.msg = msg;
        result.code = ResponseStateConstant.TOKENERROR;
        return result;
    }
}